﻿Imports DTO

Public Class DAEmployee

    Inherits DataProvider

    ''' <summary>
    ''' Config server
    ''' </summary>
    ''' <param name="serverName"></param>
    ''' <remarks></remarks>
    Shared Sub ConfigServerName(ByVal strConnect As String)

        ' call constructor base class
        ConfigServer(strConnect)

    End Sub

    Shared Sub OpenConnect()

        Open()

    End Sub

    Shared Sub CloseConnect()

        Close()

    End Sub

    Shared Function GetAllEmployee() As DataTable

        Return Query("GetAllEmployee")

    End Function



    ''' <summary>
    ''' Get all ID registered in Terminal user data
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetIdTerminalUserData() As DataTable

        Return Query("GetIDTerminalUserData")

    End Function

    ''' <summary>
    ''' Get all ID registered in Employee
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetIdEmployee() As DataTable

        Return Query("GetIdEmployee")

    End Function

    ''' <summary>
    ''' Function search employee in organization with No or Name
    ''' </summary>
    ''' <param name="organNo"></param>
    ''' <param name="strSearch"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetEmployee(ByVal organNo As String, ByVal strSearch As String) As DataTable

        Return Query("GetEmployee", New String() {"@organNo", "@str"}, New Object() {organNo, strSearch})

    End Function


    ''' <summary>
    ''' Get employee information 
    ''' </summary>
    ''' <param name="id"></param>
    ''' <param name="no"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function GetEmpByIdNo(ByVal id As String, ByVal no As String) As DataTable

        Return Query("GetEmployeeByIdNo", New String() {"@id", "@no"}, New Object() {id, no})

    End Function

    ''' <summary>
    ''' delete employee set status = 1 with expiration to = 99999999
    ''' </summary>
    ''' <param name="id"></param>
    ''' <param name="no"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function DeleteEmployee(ByVal id As String, ByVal no As String, ByVal exTo As String) As Integer

        Return Update("DeleteEmployee", New String() {"@id", "@no", "exTo"}, New Object() {id, no, exTo})

    End Function

    ''' <summary>
    ''' delelte employee set status = 1
    ''' </summary>
    ''' <param name="id"></param>
    ''' <param name="no"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function DeleteEmployeeWithoutExTo(ByVal id As String, ByVal no As String) As Integer

        Return Update("DeleteEmployeeWithouExTo", New String() {"@id", "@no"}, New Object() {id, no})

    End Function


    ''' <summary>
    ''' Add new employee
    ''' </summary>
    ''' <param name="dtoEmployee"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Shared Function AddEmployee(ByVal dtoEmployee As DTOEmployee) As Integer

        Dim params As String() = New String() {"@id", "@no", "@orgNo", "@timNo", "@lasName", "@firName", "@expFrom", "@expTo",
                                             "@pasWord", "@datOfBirth", "@idCard", "@homPhone", "@celPhone", "@regAddress",
                                             "@curAddress", "@email", "@marStatus", "@expTimFrom", "@expTimTo", "@gender"}

        Dim values As Object() = New Object() {dtoEmployee.IdProperty, dtoEmployee.EmpNoProperty, dtoEmployee.OrgNoProperty, dtoEmployee.TimNoProperty,
                                               dtoEmployee.LasNameProperty, dtoEmployee.FirNameProperty, dtoEmployee.ExpFromProperty, dtoEmployee.ExpToProperty,
                                               dtoEmployee.LoginPwdProperty, dtoEmployee.DatOfBirthProperty, dtoEmployee.IdCardProperty, dtoEmployee.HomPhoneProperty,
                                               dtoEmployee.CelPhoneProperty, dtoEmployee.RegAddressProperty, dtoEmployee.CurrAddressProperty, dtoEmployee.EmailProperty,
                                               dtoEmployee.MarStatusProperty, dtoEmployee.ExpTimFromProperty, dtoEmployee.ExpTimToProperty, dtoEmployee.GenderProperty}

        Return Update("AddEmployee", params, values)

    End Function

    Shared Function ModifyEmployee(ByVal dtoEmployee As DTOEmployee) As Integer

        Dim params As String() = New String() {"@id", "@no", "@orgNo", "@timNo", "@lasName", "@firName", "@expFrom", "@expTo",
                                            "@pasWord", "@datOfBirth", "@idCard", "@homPhone", "@celPhone", "@regAddress",
                                            "@curAddress", "@email", "@marStatus", "@expTimFrom", "@expTimTo", "@gender"}

        Dim values As Object() = New Object() {dtoEmployee.IdProperty, dtoEmployee.EmpNoProperty, dtoEmployee.OrgNoProperty, dtoEmployee.TimNoProperty,
                                              dtoEmployee.LasNameProperty, dtoEmployee.FirNameProperty, dtoEmployee.ExpFromProperty, dtoEmployee.ExpToProperty,
                                              dtoEmployee.LoginPwdProperty, dtoEmployee.DatOfBirthProperty, dtoEmployee.IdCardProperty, dtoEmployee.HomPhoneProperty,
                                              dtoEmployee.CelPhoneProperty, dtoEmployee.RegAddressProperty, dtoEmployee.CurrAddressProperty, dtoEmployee.EmailProperty,
                                              dtoEmployee.MarStatusProperty, dtoEmployee.ExpTimFromProperty, dtoEmployee.ExpTimToProperty, dtoEmployee.GenderProperty}


        Return Update("ModifyEmployee", params, values)

    End Function

    Shared Function GetEmployeeNoFromEnrollNo(ByVal dtoEmployee As DTOEmployee) As String
        Return Query("GetEmployeeNoFromEnrollNo", {"@enrollNo"}, {dtoEmployee.IdProperty}).Rows.Item(0).Item(0).ToString()
        'MsgBox(Query("GetEmployeeNoFromEnrollNo", {"@enrollNo"}, {dtoEmployee.IdProperty}).Rows.Item(0).Item(0).ToString())
    End Function

    Shared Function CheckUsernameAndPassword(ByVal dtoEmployee As DTOEmployee) As Integer
        Return NonQueryReturn("CheckUsernameAndPassword", {"@employee_No", "@login_Password"}, {dtoEmployee.EmpNoProperty, dtoEmployee.LoginPwdProperty})
        'MsgBox(NonQueryReturn("CheckUsernameAndPassword", {"@employee_No", "@login_Password"}, {dtoEmployee.EmpNoProperty, dtoEmployee.LoginPwdProperty}))
    End Function

End Class
